package com.yc.proxy;

import com.yc.proxy.user.domain.User;
import com.yc.proxy.user.service.IUserService;
import com.yc.proxy.user.service.impl.UserServiceImpl;

/**
 * Title:<br>
 * Description: <br>
 * Author:陈圆(chenyuan@bosssoft.com.cn) <br>
 * Date:2020/9/14
 */
public class ProxyTest {

    public static void main(String[] args) {
        ProxyTest proxyTest = new ProxyTest();
        proxyTest.test1();

//        proxyTest.test2();
    }

    /** jdk 接口代理测试 **/
    private void test1() {
        ProxyFactory proxyFactory = new ProxyFactory(new UserServiceImpl());
        IUserService proxy = (IUserService) proxyFactory.createProxy();
        User u = new User();
        proxy.save(u);
        System.out.println(proxy instanceof IUserService);
        System.out.println(proxy instanceof UserServiceImpl);
    }

    /** cglib 代理测试**/
    private void test2() {
//        EnhancerFactory enhancerFactory = new EnhancerFactory(new UserServiceImpl());
//        IUserService userService = (IUserService) enhancerFactory.createEnhancer();
//        User u = new User();
//        userService.save(u);
//        System.out.println(userService instanceof IUserService);
    }
}
